import 'package:date_format/date_format.dart';
import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:flutter_widgets_pc/config/kq_global.dart';
import 'package:flutter_widgets_pc/resources/kq_theme_colors.dart';
import 'package:flutter_widgets_pc/utils/dialog_util.dart';
import 'package:flutter_widgets_pc/utils/str_util.dart';
import 'package:flutter_widgets_pc/utils/toast_util.dart';
import 'package:flutter_widgets_pc/widgets/bottomSheet/kq_botton_sheet_manger.dart';
import 'package:flutter_widgets_pc/widgets/bottomSheet/sheets/kq_action_list_bottom_sheet.dart';
import 'package:flutter_widgets_pc/widgets/button/kq_outline_button.dart';
import 'package:flutter_widgets_pc/widgets/formItem/kq_empty_item_view.dart';
import 'package:flutter_widgets_pc/widgets/titleBar/kq_title_bar.dart';

/// 对话框演示
class DialogDemoPage extends StatefulWidget {
  const DialogDemoPage({Key? key}) : super(key: key);

  @override
  DialogDemoPageState createState() => DialogDemoPageState();
}

class DialogDemoPageState extends State<DialogDemoPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: KqHeadBar(
        headTitle: '对话框演示',
        back: () {
          Get.back();
        },
      ),
      body: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          children: [
            Row(
              children: [
                Expanded(
                  child: Wrap(
                    spacing: 10,
                    runSpacing: 10,
                    children: [
                      KqOutlineButton(
                        title: '消息对话框',
                        onTap: () {
                          KqDialog.showMsgDialog(title: '提示', msg: '任务单删除成功！');
                        },
                      ),
                      KqOutlineButton(
                        title: '确认对话框',
                        onTap: () {
                          KqDialog.showConfirmDialog(
                            title: '删除任务单',
                            msg: '确定删除该任务单吗？',
                            onConfirm: () {
                              KqToast.showNormal('删除成功！');
                            },
                          );
                        },
                      ),
                      KqOutlineButton(
                        title: '中间列表对话框',
                        onTap: () {
                          KqDialog.showListDialog([
                            "很长很长很长很长很长很长很长很长长很长长很长",
                            "222",
                            "333",
                            "444",
                            "555",
                            "666",
                            "777",
                            "888"
                          ]);
                        },
                      ),
                      KqOutlineButton(
                        title: '底部列表对话框',
                        onTap: () {
                          KqBottomSheetManager.showActionList(
                              [
                                KqActionListData(
                                    item: '很长很长很长很长很长很长很长很长长很长长很长很长长很长很长长很长',
                                    itemId: '111'),
                                KqActionListData(item: '222'),
                                KqActionListData(
                                    item: '333',
                                    textColor: KqThemeColors.textRed),
                                KqActionListData(item: '444'),
                                KqActionListData(
                                    item: '555',
                                    textColor: KqThemeColors.textYellow),
                                KqActionListData(item: '666'),
                                KqActionListData(item: '777'),
                                KqActionListData(item: '888'),
                              ],
                              title: '标题内容',
                              callback: (int index, KqActionListData item) {
                            KqToast.showNormal(item.item);
                          });
                        },
                      ),
                      KqOutlineButton(
                        title: '输入对话框（单行）',
                        onTap: () {
                          KqDialog.showInputDialog(
                            '请输入产品名称',
                            onEmptyCallback: () =>
                                KqToast.showNormal('产品名称不能为空'),
                            onConfirm: (value) {
                              KqToast.showNormal(value);
                            },
                          );
                        },
                      ),
                      KqOutlineButton(
                        title: '输入对话框(多行)',
                        onTap: () {
                          KqDialog.showInputDialog(
                            '请输入撤回原因',
                            multiline: true,
                            middleBtnText: '测试中间',
                            onMiddleBtnClick: (value) {
                              KqToast.showNormal('中间点击$value');
                            },
                            onConfirm: (value) {
                              KqToast.showNormal(value);
                            },
                          );
                        },
                      ),
                      KqOutlineButton(
                        title: '日期选择',
                        onTap: () {
                          KqDialog.showDatePicker(
                            '选择日期',
                            initialDateTime: DateTime.parse('2021-09-08'),
                            onConfirm: (dateTime, selectedIndex) {
                              KqToast.showNormal(
                                  StrUtil.formatDatetimeYMD(dateTime));
                            },
                          );
                        },
                      ),
                      KqOutlineButton(
                        title: '时间选择',
                        onTap: () {
                          KqDialog.showTimePicker(
                            '选择时间',
                            onConfirm: (dateTime, selectedIndex) {
                              KqToast.showNormal(
                                  StrUtil.formatDatetimeHms(dateTime));
                            },
                          );
                        },
                      ),
                      KqOutlineButton(
                        title: '日期时间选择',
                        onTap: () {
                          KqDialog.showDateTimePicker(
                            '选择日期和时间',
                            onConfirm: (dateTime, selectedIndex) {
                              KqToast.showNormal(
                                  StrUtil.formatDatetimeYMDHms(dateTime));
                            },
                          );
                        },
                      ),
                      KqOutlineButton(
                        title: '日期选择底部',
                        onTap: () {
                          KqBottomSheetManager.showDatePicker(
                            title: '选择日期',
                            onConfirm: (dateTime, selectedIndex) {
                              KqToast.showNormal(
                                  StrUtil.formatDatetimeYMD(dateTime));
                            },
                          );
                        },
                      ),
                      KqOutlineButton(
                        title: '时间选择底部',
                        onTap: () {
                          KqBottomSheetManager.showTimePicker(
                            title: '选择时间',
                            onConfirm: (dateTime, selectedIndex) {
                              KqToast.showNormal(
                                  StrUtil.formatDatetimeHms(dateTime));
                            },
                          );
                        },
                      ),
                      KqOutlineButton(
                        title: '日期时间选择底部',
                        onTap: () {
                          KqBottomSheetManager.showDateTimePicker(
                            title: '选择日期和时间',
                            onConfirm: (dateTime, selectedIndex) {
                              KqToast.showNormal(
                                  StrUtil.formatDatetimeYMDHms(dateTime));
                            },
                          );
                        },
                      ),
                      KqOutlineButton(
                        title: '类似原因对话框',
                        onTap: () {
                          KqDialog.showReasonDialog(
                            title: '选择返修原因',
                            renderTitleCallback: ((index) {
                              return '索引$index';
                            }),
                            totalCount: 10,
                            callBack: (index) {
                              print('点击了这一行---------$index');
                            },
                          );
                        },
                      ),
                      KqOutlineButton(
                        title: '日期范围选择底部',
                        onTap: () {
                          KqBottomSheetManager.showDateRangePicker(
                            title: '选择日期',
                            hintText: '最长可查找时间跨度XX的任务单',
                            onConfirm: (startTime, endTime) {
                              if (startTime.millisecondsSinceEpoch >
                                  endTime.millisecondsSinceEpoch) {
                                KqToast.showNormal('开始日期不能大于结束日期');
                                return false;
                              }
                              KqToast.showNormal(
                                  "${StrUtil.formatDatetimeYMD(startTime)}到${StrUtil.formatDatetimeYMD(endTime)}");
                              return true;
                            },
                          );
                        },
                      ),
                      KqOutlineButton(
                        title: '时间范围选择底部',
                        onTap: () {
                          KqBottomSheetManager.showTimeRangePicker(
                            title: '选择时间',
                            hintText: '最长可查找时间跨度XX的任务单',
                            onConfirm: (startTime, endTime) {
                              if (startTime.millisecondsSinceEpoch >
                                  endTime.millisecondsSinceEpoch) {
                                KqToast.showNormal('开始时间不能大于结束时间');
                                return false;
                              }
                              KqToast.showNormal(
                                  "${StrUtil.formatDatetimeHms(startTime)}到${StrUtil.formatDatetimeHms(endTime)}");
                              return true;
                            },
                          );
                        },
                      ),
                      KqOutlineButton(
                        title: '日期时间范围选择底部',
                        onTap: () {
                          KqBottomSheetManager.showDateTimeRangePicker(
                            title: '选择日期和时间',
                            hintText: '最长可查找时间跨度XX的任务单',
                            withMinute: false,
                            withSecond: false,
                            resultFontSize: 14,
                            onConfirm: (startTime, endTime) {
                              if (startTime.millisecondsSinceEpoch >
                                  endTime.millisecondsSinceEpoch) {
                                KqToast.showNormal('开始时间不能大于结束时间');
                                return false;
                              }
                              KqToast.showNormal(
                                  "${StrUtil.formatDatetimeYMDHms(startTime)}到${StrUtil.formatDatetimeYMDHms(endTime)}");
                              return true;
                            },
                          );
                        },
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
